package com.arr;

public class Kid {
	private int id;
	private Kid left;
	private Kid right;
	
	Kid()
	{
		this.id = 0;
		this.left = this.right = null;
	}
	
	Kid(int id,Kid left,Kid right)
	{
		this.id = id;
		this.left = left;
		this.right = right;
	}
	
	public void setID(int id)
	{
		this.id = id;
	}
	
	public int getID()
	{
		return this.id;
	}
	
	public void setLeft(Kid left)
	{
		this.left = left;
	}
	
	public Kid getLeft()
	{
		return this.left;
	}
	
	public void setRight(Kid right)
	{
		this.right = right;
	}
	
	public Kid getRight()
	{
		return this.right;
	}
}

class Circle {
	private int count = 0;
	private Kid first;
	private Kid last;
	
	Circle()
	{
		this.first = this.last = null;
	}
	
	Circle(int n)
	{
		for(int i = 0;i<n;i++)
		{
			addKid();
		}
	}
	
	public void addKid()
	{
		Kid k = new Kid();
		k.setID(this.count);
		if(this.count <= 0)
		{
			this.first = this.last = k;
		}
		else
		{
			last.setRight(k);
			k.setLeft(last);
			k.setRight(first);
			first.setLeft(k);
			last = k;
		}
		this.count++;
	}
	
	public void deleteKid(Kid k)
	{
		if(this.count <=0)
		{
			return;
		}
		else if(this.count == 1)
		{
			this.first = this.last = null;
		}
		else
		{
			k.getLeft().setRight(k.getRight());
			k.getRight().setLeft(k.getLeft());
			
			if(k == first)
			{
				first = k.getRight();
				first.setLeft(last);
			}
			if(k == last)
			{
				last = k.getLeft();
				last.setRight(first);
			}
		}
		
		this.count--;
	}
	
	public void setCount(int c)
	{
		this.count = c;
	}
	
	public int getCount()
	{
		return this.count;
	}
	
	public void setFirst(Kid first)
	{
		this.first = first;
	}
	
	public Kid getFirst()
	{
		return this.first;
	}
	
//	public Kid getKid(int c)
//	{
//		Kid nextKid = first;
//		for(int i = 1;i<= c;i++)
//		{
//		   	nextKid = nextKid.getRight();
//		}
//		return nextKid;
//	}
//	
	public void printKid()
	{
		
		System.out.println("ID:"+this.first.getID());
		System.out.println("ID:"+this.last.getID());
	}
	
}
